package com.zkh360.service.message.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zkh360.service.message.controller.base.BaseController;

/**
 * 登录controller
 * 
 * @author chuanxi.zhao
 *
 */
@Controller
public class LoginController extends BaseController {

	@GetMapping("/login")
	public String login() {
		return "login";
	}

	@GetMapping("/index")
	public ModelAndView index() {
		ModelAndView view = new ModelAndView("index");
		return view;
	}

	/**
	 * 登出
	 * 
	 * @param request
	 *            request请求
	 * @param authentication
	 *            权限
	 */
	@GetMapping("/logout")
	public void logout(HttpServletRequest request, Authentication authentication) {
		Assert.notNull(request, "HttpServletRequest required");
		HttpSession session = request.getSession(false);
		if (session != null) {
			session.invalidate(); // 使当前会话失效
		}
		SecurityContextHolder.clearContext(); // 清空安全上下文
	}
	
	@GetMapping("/resume")
	public String resume() {
		return "resume";
	}


}
